//index.js
//获取应用实例
var app = getApp()
Page({
  data: {  
      UserName:'',
      Password:'',
      Err:''
  },

   bindUserNameKeyInput: function(e) {
    this.setData({
     
          UserName:e.detail.value 
        
    })
  },

  bindPassoredKeyInput:function(e){
      this.setData({ 
        Password:e.detail.value 
        })
  },
  bindViewLogin:function(){
    var that=this;

      this.setData({ 
              Err:'' 
              }) ;
    wx.request({
    url: 'http://localhost:3000/api/login/'+
    this.data.UserName+'/'+this.data.Password ,
    data: {},
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function(res){
      // success 
       if(res.data.code =="UserDoesNotExists"){
            that.setData({ 
              Err:'用户不存在' 
              }) ;
      }
      else  if(res.data.code =="UserDoesNotExists"){
            that.setData({ 
                  Err:'密码错误！' 
                  }) ;  
      }
     else{ 

// _id
// :
// "5819ec21039f3e6a271702fe"
// email
// :
// "admin@topcheer.com"
// mobile
// :
// "13817691727"
// name
// :
// "管理员"
// password
// :
// "123"
// username
// :
// "admin
 
        wx.navigateTo({
            url: '/pages/main/main?userName='+res.data.data.name+
            '&mobile='+res.data.data.mobile
          });

    }
  },
  fail: function() {
    // fail
  },
  complete: function() {
    // complete
  }
}) 
  },
   
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
